package com.kele.test.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class RabbitMQConfig_Fanout {

    private static final String QUEUE_NAME_1 = "fanout_Q1";
    private static final String QUEUE_NAME_2 = "fanout_Q2";
    private static final String QUEUE_NAME_3 = "fanout_Q3";
    private static final String EXCHANGE_NAME = "exchange_fanout";

    @Bean(QUEUE_NAME_1)
    public Queue queueDeclare_fanout1(){
        //return new Queue(QUEUE_NAME,true);
        return QueueBuilder.durable(QUEUE_NAME_1).build();
    }
    @Bean(QUEUE_NAME_2)
    public Queue queueDeclare_fanout2(){
        //return new Queue(QUEUE_NAME,true);
        return QueueBuilder.durable(QUEUE_NAME_2).build();
    }
    @Bean(QUEUE_NAME_3)
    public Queue queueDeclare_fanout3(){
        //return new Queue(QUEUE_NAME,true);
        return QueueBuilder.durable(QUEUE_NAME_3).build();
    }

    @Bean(EXCHANGE_NAME)
    public Exchange exchangeDeclare_fanout(){
        return ExchangeBuilder.directExchange(EXCHANGE_NAME).durable(true).build();
    }

    @Bean
    public Binding bindingDeclare_fanout1(
            @Qualifier(QUEUE_NAME_1) Queue queue,
            @Qualifier(EXCHANGE_NAME) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("anything").noargs();
    }

    @Bean
    public Binding bindingDeclare_fanout2(
            @Qualifier(QUEUE_NAME_2) Queue queue,
            @Qualifier(EXCHANGE_NAME) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("anything").noargs();
    }

    @Bean
    public Binding bindingDeclare_fanout3(
            @Qualifier(QUEUE_NAME_3) Queue queue,
            @Qualifier(EXCHANGE_NAME) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("anything").noargs();
    }
}
